﻿using System;

namespace PacMan3D.Utils
{
    /// <summary>
    /// This class represents a RGBA Color, composed by floats.
    /// </summary>
    public class RGBAColor
    {
        public float Red { get; set; }
        public float Green { get; set; }
        public float Blue { get; set; }
        public float Alpha { get; set; }

        public RGBAColor(float red, float green, float blue, float alpha) 
        {
            this.Red = red;
            this.Green = green;
            this.Blue = blue;
            this.Alpha = alpha;
        }

        public RGBAColor(float red, float green, float blue)
            : this(red, green, blue, 1.0f) {}

        public RGBAColor(StandardColors stdColor, float alpha)
        {
            switch (stdColor)
            {
                case StandardColors.Red:
                    this.Red = 1.0f;
                    this.Green = 0.0f;
                    this.Blue = 0.0f;
                    break;

                case StandardColors.Green:
                    this.Red = 0.0f;
                    this.Green = 1.0f;
                    this.Blue = 0.0f;
                    break;

                case StandardColors.Blue:
                    this.Red = 0.0f;
                    this.Green = 0.0f;
                    this.Blue = 1.0f;
                    break;

                case StandardColors.Yellow:
                    this.Red = 1.0f;
                    this.Green = 1.0f;
                    this.Blue = 0.0f;
                    break;

                case StandardColors.Black:
                    this.Red = 0.0f;
                    this.Green = 0.0f;
                    this.Blue = 0.0f;
                    break;

                case StandardColors.White:
                    this.Red = 1.0f;
                    this.Green = 1.0f;
                    this.Blue = 1.0f;
                    break;

                case StandardColors.Purple:
                    this.Red = 0.5f;
                    this.Green = 0.0f;
                    this.Blue = 0.5f;
                    break;

                case StandardColors.Pink:
                    this.Red = 1.0f;
                    this.Green = 0.75f;
                    this.Blue = 0.8f;
                    break;

                case StandardColors.Orange:
                    this.Red = 1.0f;
                    this.Green = 0.65f;
                    this.Blue = 0.0f;
                    break;

                case StandardColors.Gray:
                    this.Red = 0.2f;
                    this.Green = 0.2f;
                    this.Blue = 0.2f;
                    break;

                case StandardColors.LightGray:
                    this.Red = 0.08f;
                    this.Green = 0.08f;
                    this.Blue = 0.08f;
                    break;

                case StandardColors.Brawn:
                    this.Red = 0.6f;
                    this.Green = 0.4f;
                    this.Blue = 0.1f;
                    break;

                case StandardColors.FogColor:
                    this.Red = 0.9f;
                    this.Green = 0.9f;
                    this.Blue = 0.9f;                    
                    break;
            }
            this.Alpha = alpha;
        }

        public override string ToString()
        {
            return "Color{Red: " + this.Red + ", Green: " + this.Green + ", Blue: " + this.Blue + ", Alpha: " + this.Alpha + "}";
        }


        private static int palleteIndex;
        public static RGBAColor GetPalleteColorByIndex(int index, float alpha)
        {
            palleteIndex = index % 7;

            switch(index)
            {
                case 1:
                    return new RGBAColor(StandardColors.Blue, alpha);
                
                case 2:
                    return new RGBAColor(StandardColors.Green, alpha);

                case 3:
                    return new RGBAColor(StandardColors.Orange, alpha);

                case 4:
                    return new RGBAColor(StandardColors.Red, alpha);

                case 5:
                    return new RGBAColor(StandardColors.Purple, alpha);

                case 6:
                    return new RGBAColor(StandardColors.Pink, alpha);

                default:
                    return new RGBAColor(StandardColors.Black, alpha);
            }
        }
    }

    public enum StandardColors 
    {
        Red,
        Green,
        Blue,
        Yellow,
        Black,
        White,
        Purple,
        Pink,
        Orange,
        Gray,
        LightGray,
        Brawn,
        FogColor
    }
}
